package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Food;
import com.neusoft.elmboot.service.FoodService;

@RestController
@RequestMapping("/Food")
public class FoodController {

	@Autowired
	private FoodService foodService;

	@GetMapping("/FoodList")
	public List<Food> listFoodByBusinessId(Food food) throws Exception {
		return foodService.listFoodByBusinessId(food.getBusinessId());
	}

	// get food by id
	@GetMapping("/FoodId")
	public Food getFoodById(Food food) throws Exception {
		return foodService.getFoodById(food.getFoodId());
	}

	// save food
	@PostMapping("/FoodId")
	public int saveFood(Food food) throws Exception {
		return foodService.saveFood(food);
	}

	// update food
	@PutMapping("/FoodId")
	public int updateFood(Food food) throws Exception {
		System.out.println("Received food object: " + food);
		return foodService.updateFood(food);
	}

	// remove food
	@DeleteMapping("/FoodId")
	public int removeFood(Food food) throws Exception {
		return foodService.removeFood(food.getFoodId());
	}

	// update count
	@PutMapping("/FoodCount")
	public int updateFoodCount(Integer foodCount, Integer foodId) {
		return foodService.updateFoodCount(foodCount, foodId);
	}
}